package com.bytezreo.objectclass;

import java.util.Objects;

public class Customer
{
	private String name;
	private int age;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public Customer() {
		super();
	}
	public Customer(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}
	
	
	
	//自动生成  equals() 方法
	@Override
	public boolean equals(Object obj) {
		System.out.println("执行自动重写 equals()方法：");
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Customer other = (Customer) obj;
		return age == other.age && Objects.equals(name, other.name);
	}
	
	
	//手动实现 equals()
	//重写原则：比较两个对象的实体内容是否相同
	
//	@Override
//	public boolean equals(Object obj)
//	{
//		System.out.println("执行手动重写 equals()方法：");
//	  if (this == obj) 
//	  {
//            return true;
//      }
//	  if(obj instanceof Customer)
//	  {
//		  Customer cust = (Customer)obj;
//		  //比较两个对象的每个属性是否都相同
////		  if(this.age == cust.age && this.name.equals(cust.name))
////		  {
////			  return true;
////		  }
////		  else
////		  {
////			  return false;
////		  }
//		  
//		  //或者
//		  return this.age == cust.age && this.name.equals(cust.name);
//		  
//		  
//	  }
//	  return false;
//	}
//	
	
	

	//手动写的
//@Override
//public String toString() {
//
//	return "Customer[name ="+name+",age = "+ age+"]";
//	
//}
	

	//自动写的
	
	@Override
	public String toString() {
		return "Customer [name=" + name + ", age=" + age + "]";
	}
	
	
}


























































































